<template>
  <div>
    <div>
      <header>
        <el-row type="flex" class="row-bg" justify="space-between">
          <router-link to="">
            <el-col :span="6">
              <div class="grid-content bg-purple">
                <span class="iconfont" @click="goback">&#xe609;</span>
              </div>
            </el-col>
          </router-link>
          <div style="margin-right: 40.3%;color: #fff; font-size: 20px;">Ta的资料</div>
        </el-row>
      </header>
      <div style="height: 40.8px"></div>
    </div>
    <div class="demo-fit">
      <div class="block">
        <el-avatar shape="square" :size="70" :fit="fits" :src="userInfo.userAvatar"></el-avatar>
        <div class="info">
          <div class="nickname">{{userInfo.nickName}}</div>
          <div class="id">{{'ID:'+userInfo.userId}}</div>
          <div class="desc">{{'简介：' + userInfo.userDesc}}</div>
        </div>
      </div>
    </div>
    <div style="height: 5px; width: 100%; background-color: #eee; margin:5px 0 5px 0;"></div>
    <el-tabs v-model="activeName" :stretch="true">
      <el-tab-pane label="Ta发布的" name="first">
        <el-row>
          <el-col :xs="12" :sm="6" :md="4" :lg="3" :xl="6" v-for="item in userlunched" :key="item.id">
            <el-card :body-style="{ padding: '5px'}" class="el-card">
              <img :src="item.activityImg" class="image" />
              <div class="div-content">
                <span>{{item.activityName}}</span>
                <div class="bottom clearfix">
                  <time class="time">{{item.currentDate}}</time> 
                  <time class="num">{{item.tookNumber+'/'+item.limitNumber}}</time>
                </div>
              </div>
              <div style="display: flex;flex-direction: row-reverse;">
                <el-button class="button" size="medium" type="primary" @click="todetail(item.activityId)">查看</el-button>
              </div>
            </el-card>
          </el-col>
        </el-row>
      </el-tab-pane>
      <el-tab-pane label="Ta获得的评价" name="second">
        <div class="appraise-all" v-for="item in userappraise" :key="item.userId">
          <div class="appraise-avatar">
            <el-avatar shape="square" :size="30" :fit="fits" :src="item.userAvatar"></el-avatar>
          </div>
          <div class="appraise-show">
            <div class="name-level">
              <div class="appraise-nickname">
                {{item.userName}}
              </div>
              <div class="level">
                {{'评价等级：'+ item.appraiseLevel+'!'}}
              </div>
            </div>
            <div class="appraise-content">
              {{item.userContent}}
            </div>
            <div class="appraise-time">
              {{item.appraiseTime}}
            </div>
          </div>
        </div>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import axios from 'axios'
export default {
    name: 'UserDetail',
    props: {
      userId: String
    },
    data() {
      return {
        activeName: 'first',
        fits: 'contains',
        userInfo: {},
        userlunched: [],
        userappraise: [],
      }
    },
    methods: {
      todetail(activityId) {
        this.$router.push('/detail/'+activityId)
      },
      goback() {
        window.history.go(-1);
      },
      getHomeInfo () {
          axios.get('/static/mock/userdetail.json')
              .then(this.getHomeInfoSucc)
      },
      getHomeInfoSucc (res) {
          res = res.data
          if (res.ret && res.data) {
              const data = res.data
              this.userInfo = data.userInfo
              this.userlunched = data.userlunched
              this.userappraise = data.userappraise
          }else {
              alert('数据获取失败')
          }
          console.log(res)
      }
    },
    mounted () {
        this.getHomeInfo()
    }
}
</script>

<style scoped>
  header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 99999;
    line-height: 2.5rem;
    background: #67C23A;
    text-align: center;
    }
  .iconfont {
    font-size: 1.6rem;
    color: #fff;
    margin-left: .4rem;
    }
    .block {
      display: flex;
      margin-left: 20px;
      margin-top: 15px;
      margin-bottom: 10px;
    }
    .info {
      flex-direction:column;
      align-items: center;
    }
    .nickname {
      display: flex;
      align-items: center;
      height: 32.5px;
      width: 150px;
      padding: 0 0 0 20px;
    }
    .id {
      display: flex;
      align-items: center;
      height: 32.5px;
      width: 150px;
      padding: 0 0 0 20px;
      font-size: 12px;
      color: #C0C4CC
    }
    .desc {
      display: flex;
      align-items: center;
      height: 35px;
      width: 160px;
      padding: 0 0 0 20px;
      font-size: 12px;
      color: #C0C4CC
    }
    .time {
    font-size: 13px;
    color: #999;
  }
  .num {
  float: right;
  font-size: 13px;
  color: #999;
  width: 36.1px;
  text-align: center;
  }
  .bottom {
    margin-top: 13px;
    line-height: 12px;
  }
  .button {
    margin-top: 6px;
    width: 100px;
  }
  .image {
    width: 100%;
    display: block;
  }
  .clearfix:before,
  .clearfix:after {
      display: table;
      content: "";
  }
  .div-content {
    padding: 12px 12px 0 12px;
  }
  .el-card {
    height: 300px;
  }
    .appraise-avatar {
    padding: 0 0 0 10px;
  }
  .appraise-show {
    padding: 0 0 0 15px;
    border-bottom: 1px solid #eee;
    width: 100%;
  }
  .appraise-nickname {
    font-size: 12px;
    color: #C0C4CC;
  }
  .appraise-content {
    font-size: 13.5px;
    margin-top: 4px;
    margin-bottom: 4px;
  }
  .appraise-time {
    font-size: 12px;
    color: #C0C4CC;
    margin-bottom: 5px;
  }
  .appraise-all {
    display: flex;
    padding: 5px 0 0 0;
  }
  .name-level {
    display: flex;
    align-items: center;
  }
  .level {
    float: right;
    margin-left: 30%;
  }
</style>